import { dom } from "./dom.js"
import { _popover } from './popover.js'
// export const _btn = (text, options, events) => {
//   return dom.button(text, {
//     class: 'button',
//     ...options,
//     type: 'button'

//   }, events)
// }

export const _btn = (t) => {

  return dom.button(t.text, {
    class: `form-btn${t.className ? ' ' + t.className : ''} ${t.popover ? ' popover' : ''}`
  }, {
    click: (e) => {
      // let model = {}
      // fields.filter(t => t.field).forEach(t => { //['text','number','select'].includes(t.type)
      //   let key = t.field
      //   let item = _query( `[name=${key}]`,form)
      //   model[key] = item.value
      // })
      // let scope = {
      //   model,
      //   form,
      //   emit //事件
      // }
      // 弹窗
      if (t.popover) {
        document.body.appendChild(_popover(t.popover, e.target))
      }
      let scope = this
      t.click.call(scope, e, scope)


      // t.click.call(scope, e, scope)
    }
  })
}
